Skip to content

Add a FilteredEvent type to handle per-user data on events#19640

Merged
erikjohnston merged 8 commits intodevelopfrom
erikj/per_user_unsigned
Apr 16, 2026
Merged

Add a FilteredEvent type to handle per-user data on events#19640
erikjohnston merged 8 commits intodevelopfrom
erikj/per_user_unsigned

Conversation

@erikjohnston
Copy link
Copy Markdown
Member

@erikjohnston erikjohnston commented Apr 1, 2026

When we return events to clients we need to annotate them with the membership of the user at the time of the event, in the unsigned section. We already check the membership at the event during the visibility checks, and so we annotate events there. However, since this a per-user field we end up having to clone the event in question.

Instead, let's add a FilteredEvent class that is returned by the visibility checks, which allows returning the membership without editing the event. This has three benefits:

  1. Avoids the clones of the event.
  2. Allows us to statically check that we have filtered events before returning them to clients.
  3. We no longer edit unsigned data after event deserialization, this makes it easier to port the event class to Rust.

The last benefit is why we're doing this now, however IMV it shouldn't affect whether we want this change or not.

Reviewable commit-by-commit

@erikjohnston erikjohnston marked this pull request as ready for review April 1, 2026 16:58
@erikjohnston erikjohnston requested a review from a team as a code owner April 1, 2026 16:58
@reivilibre reivilibre self-requested a review April 15, 2026 12:44
Copy link
Copy Markdown
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via pullgoose.

Comment thread synapse/events/utils.py Outdated
Comment thread synapse/events/utils.py Outdated
Comment thread synapse/events/utils.py
@erikjohnston
Copy link
Copy Markdown
Member Author

Thanks @reivilibre

@erikjohnston erikjohnston merged commit 71781de into develop Apr 16, 2026
44 of 46 checks passed
@erikjohnston erikjohnston deleted the erikj/per_user_unsigned branch April 16, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants